import React, { Component } from 'react'
import { Redirect, Route, Switch } from 'react-router';
import memoryUtils from '../../utils/memoryUtils'
import { Layout } from 'antd';
import LeftNav from "../../components/left-nav"
import Header from "../../components/header"
import Home from "../Home";
import Category from "../Category";
import Product from "../Product";
import Role from "../Role";
import User from "../User";
import Bar from "../Charts/Bar";
import Line from "../Charts/Line";
import Pie from "../Charts/Pie";


const {  Footer, Sider, Content } = Layout;

/*
    后台管理的路由组件
 */
export default class Admin extends Component {
    render() {
        const user = memoryUtils.user;
        if(!user || !user._id) {
            // 自动跳转到登录(在render里)
            return <Redirect to="/login"/>;
        }
        return (
            <Layout style ={{minHeight:"100%"}}>
              <Sider><LeftNav /></Sider>
              <Layout>
                <Header></Header>
                <Content style={{margin:20 ,backgroundColor:"#fff"}}>
                  <Switch>
                    <Route path="/home" component={Home}/>
                    <Route path="/category" component={Category}/>
                    <Route path="/product" component={Product}/>
                    <Route path="/role" component={Role}/>
                    <Route path="/user" component={User}/>
                    <Route path="/charts/bar" component={Bar}/>
                    <Route path="/charts/line" component={Line}/>
                    <Route path="/charts/pie" component={Pie}/>
                    <Redirect to="/home" />
                  </Switch>
                </Content>
                <Footer style={{textAlign:"center", color:"#cccccc"}}>推荐使用谷歌浏览器,可以获得更佳页面操作体验</Footer>
              </Layout>
            </Layout>
        )
    }
}
